package com.foo.Bussinesstest;

import static org.junit.Assert.*;

import org.restaurantexample.www.restaurantservice.GetAllRestaurantData;
import org.restaurantexample.www.restaurantservice.GetAllRestaurantDataResponse;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByCusine;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByCusineResponse;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByName;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByNameResponse;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByRating;
import org.restaurantexample.www.restaurantservice.GetRestaurantInfoByRatingResponse;
import org.restaurantexample.www.restaurantservice.RestaurantList;
import org.junit.Test;

import org.restaurantexample.ws.RestaurantLogic;;

public class RestaurantBITestcases {

	RestaurantLogic restaurantBI = new RestaurantLogic();
	@Test
	public void testGetRestaurantInfoByCusine() {
		try
		{
			GetRestaurantInfoByCusine getRestaurant
											= new GetRestaurantInfoByCusine();
			GetRestaurantInfoByCusineResponse response = null;
			
			getRestaurant.setIn("Indian");
			response = restaurantBI.getRestaurantInfoByCusine(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(11, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
			
			getRestaurant.setIn("Chinese");
			response = restaurantBI.getRestaurantInfoByCusine(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(4, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
			
			getRestaurant.setIn("Italian");
			response = restaurantBI.getRestaurantInfoByCusine(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(6, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
			
			getRestaurant.setIn("Mexican");
			response = restaurantBI.getRestaurantInfoByCusine(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(3, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
		}
		catch(Exception e)
		{
			fail(e.getMessage());
		}
	}

	@Test
	public void testGetRestaurantInfoByName() {
		try
		{
			GetRestaurantInfoByName getRestaurant
											= new GetRestaurantInfoByName();
			getRestaurant.setIn("Acapulco");
			GetRestaurantInfoByNameResponse response = null;
			
			response = restaurantBI.getRestaurantInfoByName(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals("Acapulco", response.getOut().getRestaurant_name());
			}
			else
			{
				assertNotNull(response);
			}
		}
		catch(Exception e)
		{
			fail(e.getMessage());
		}
	}

	@Test
	public void testGetRestaurantInfoByRating() {
		try
		{
			GetRestaurantInfoByRating getRestaurant
											= new GetRestaurantInfoByRating();
			
			GetRestaurantInfoByRatingResponse response = null;
			getRestaurant.setIn(4.5);
			response = restaurantBI.getRestaurantInfoByRating(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(20, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
			
			getRestaurant.setIn(3.5);
			response = restaurantBI.getRestaurantInfoByRating(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(1, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
			
			getRestaurant.setIn(4.0);
			response = restaurantBI.getRestaurantInfoByRating(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(15, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
			
			getRestaurant.setIn(5.0);
			response = restaurantBI.getRestaurantInfoByRating(getRestaurant);
			
			if(response != null && response.getOut() != null) 
			{
				assertEquals(14, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}			
		}
		catch(Exception e)
		{
			fail(e.getMessage());
		}
	}

	@Test
	public void testGetAllRestaurantData() {
		try
		{
			GetAllRestaurantData getRestaurant
											= new GetAllRestaurantData();
			getRestaurant.setIn("");
			GetAllRestaurantDataResponse response = null;
			
			response = restaurantBI.getAllRestaurantData(null);
			if(response != null && response.getOut() != null) 
			{
				assertEquals(50, response.getOut().getRestaurantList().length);
			}
			else
			{
				assertNotNull(response);
			}
		}
		catch(Exception e)
		{
			fail(e.getMessage());
		}
	}

}
